<script lang="ts">
export default {
  name: 'manage',
};
</script>

<script lang="ts" setup>

import {onMounted, reactive, ref} from 'vue';

import ModelObjectEditor from './components/ModelObjectEditor.vue';
import ModelObjectProfile from './components/ModelObjectProfile.vue';

import {RepoProductEntity} from "@/api/device/product/types";
import {getRepoCompObjectEntity} from "@/api/repo/comp/cloud/dev-template/version";

const modelObjectEditorRef = ref<any>(); // 这了的变量名称必须和<deviceDecoder-edit-dialog>的ref值一样
const modelObjectProfileRef = ref<any>(); // 这了的变量名称必须和<deviceDecoder-edit-dialog>的ref值一样

const dataState = reactive({
  // 版本ID
  versionId: '',
  // 操作名称
  operateId: '',
  entity: {} as RepoProductEntity,
});

/**
 * 刷新页面信息
 */
function handleQuery() {
  getRepoCompObjectEntity(dataState.versionId, dataState.operateId).then(({data}) => {
    modelObjectEditorRef.value.initData(data);
    modelObjectProfileRef.value.initData(data);
  });

}

function getHrefParams() {
  let tag = "/repo-comp/cloud/dev-template/version-info?";
  let start = location.href.indexOf(tag);
  if (start === 0) {
    return;
  }
  let params = location.href.substring(start + tag.length);

  let versionTag = 'versionId=';
  let versionStart = params.indexOf(versionTag);
  let objectIdTag = '&objectId=';
  let operateIdStart = params.indexOf(objectIdTag);

  dataState.versionId = params.substring(versionStart + versionTag.length, operateIdStart);
  dataState.operateId = params.substring(operateIdStart + objectIdTag.length);
}

/**
 * 响应页面安装：页面的初始化工作
 */
onMounted(() => {
  // 从地址栏获得操作方法的ID
  getHrefParams();

  // 向后台查询详细信息
  handleQuery();
});

</script>

<template>
  <div class="app-container">
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>动态解码</el-breadcrumb-item>
        <el-breadcrumb-item>版本列表</el-breadcrumb-item>
        <el-breadcrumb-item>操作列表</el-breadcrumb-item>
        <el-breadcrumb-item>版本信息</el-breadcrumb-item>
      </el-breadcrumb>
      <br>
    </div>



    <!-- 表单头：各种按钮 -->
    <model-object-profile ref="modelObjectEditorRef"
                            @query="handleQuery"
    />


    <!-- 数据表单：创建/修改 -->
    <model-object-editor ref="modelObjectProfileRef"
    />

  </div>
</template>
